#!/usr/bin/env python

import os
import sys
import db
from output import *
from info import *
from info import ProxyError, scalar, vector, values, total, len
sys.path.append('../../src/python/m5/util')
from jobfile import *

source = db.Database()
source.host = 'localhost'
source.db = 'pengfei'
source.passwd = '83658365yy'
source.user = 'pengfei'
source.connect()

#source.listRuns()
#source.listStats()

#jobfile = JobFile('test.py')

# Get the stats attributes, not the real data.
stats1 = source.getStat('system0.cpu.execute.EXEC:In-flightInsts')
stats2 = source.getStat('system0.cpu.ipc_total')
#stats2 = eval('system0.cpu.ipc')
stats3 = source.getStat('system0.cpu.dcache.HardPFResp_avg_mshr_uncacheable_latency')
stats4 = source.getStat('system0.cpu.execute.OPN:injectRate')

data4 = source.data(stats4[0])

print data4[193]
print len(stats4)

print stats4[0].type

import array
from array import array
a = array('c','12321')
print a
print type(a)
if type(a) is array:
    print 'haha'
x = a.tostring()
print x
#source.listFormulas('system0.cpu.ipc')

# Given the run and the stat, return the data for a formula
for stat2 in stats2:
    print stat2.type
#    value = source.get('crafty-dist-fm-pb-pmd-nw1-64IQ-8b-hb-3-2', stat2)
    value = source.get('crafty-simple-nc-pmd-1024IQ-8b-hb-sp-3-2', stat2)

    print value

# Given the run and the stat, return the data for a scalar
data3 = source.get('crafty-dist-fm-pb-pmd-nw1-64IQ-8b-hb-3-2', stats3[0])
print data3

#source.listRuns()
#run = source.allRunNames['crafty-dist-fm-pb-pmd-nw1-64IQ-8b-hb-3-2']
#print run.run

# Get data of a distribution
data1 = source.data(stats1[0])
#print data1.__contains__(0)
print data1[193]
#print stats1[0].desc

#sdist = SimpleDist(data1[21][-1][0], data1[21][-2][0],
#        data1[21][-3][0])

#sdist.display(stats1[0].name, stats1[0].desc, stats1[0].flags,
#        stats1[0].precision)

#vec = []
#for d in data1[21][0:stats1[0].size]:
#    vec.append(d[0])

#fdist = FullDist(data1[21][-1][0],
#                 data1[21][-2][0],
#                 data1[21][-3][0],
#                 data1[21][-4][0],
#                 data1[21][-5][0],
#                 data1[21][-6][0],
#                 vec,
#                 data1[21][-7][0],
#                 stats1[0].min,
#                 stats1[0].max,
#                 stats1[0].bktsize,
#                 stats1[0].size)

#fdist.display(stats1[0].name, stats1[0].desc, stats1[0].flags,
#        stats1[0].precision)

